package com.five.admin.controller;

import com.five.controller.BaseController;
import com.five.admin.service.ChapterService;
import com.five.entity.Chapter;
import com.five.vo.BaseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: star
 * @Date: 2021-05-21 14:06
 */
@Controller
@RequestMapping("chapter")
@Api(tags = "课程章节业务接口")
@CrossOrigin
public class ChapterController extends BaseController {

    @Autowired
    private ChapterService chapterService;

    /**
     * 通过课程id搜索章节
     * @param chapter 课程id
     * @return 章节信息
     */
    @ResponseBody
    @RequestMapping(value = "selectByCourseId",method = RequestMethod.GET)
    @ApiOperation("通过课程id获取章节信息接口")
    public BaseResultVO selectByCourseId(Chapter chapter){
        List<Chapter> chapters = chapterService.selectByCourseId(chapter);
        return successResp(chapters);
    }

    @ResponseBody
    @RequestMapping(value = "insertChapter",method = RequestMethod.POST)
    @ApiOperation("添加章节信息接口")
    public BaseResultVO insertChapter(Chapter chapter){
        chapterService.insertChapter(chapter);
        return successRespWithMessage("添加成功");
    }

    @ResponseBody
    @RequestMapping(value = "deleteChapter",method = RequestMethod.GET)
    @ApiOperation("删除章节信息接口")
    public BaseResultVO deleteChapter(Integer id){
        chapterService.deleteChapter(id);
        return successRespWithMessage("删除成功");
    }
}
